//
//  DRProgressJuxingView.m
//  ObjectiveCTools
//
//  Created by aidong on 2022/1/6.
//  Copyright © 2022 姬友大人. All rights reserved.
//

#import "DRProgressJuxingView.h"

@implementation DRProgressJuxingView

- (instancetype)init {
    if (self = [super init]) {
        self.colorBack = UIColor.greenColor;
        self.colorTint = UIColor.redColor;
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.colorBack = UIColor.greenColor;
        self.colorTint = UIColor.redColor;
    }
    return self;
}

- (void)setProgress:(CGFloat)progress {
    _progress = progress;
    dispatch_async(dispatch_get_main_queue(), ^{
        [self setNeedsDisplay];
    });
}


- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    //背景色
    [self.colorBack set];
    //画矩形
    CGContextFillRect(context, rect);
    //边框要搞成0
    CGContextSetLineWidth(context, 0.0);
    CGContextAddRect(context, CGRectMake(0, 0, rect.size.width * _progress, rect.size.height));
    //填充
    CGContextSetFillColorWithColor(context, self.colorTint.CGColor);
    //绘制路径及填充模式
    CGContextDrawPath(context, kCGPathFillStroke);
}

@end
